package com.alax.interfaces.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.alax.common.annotation.Log;
import com.alax.common.core.controller.BaseController;
import com.alax.common.core.domain.AjaxResult;
import com.alax.common.enums.BusinessType;
import com.alax.interfaces.domain.ApiInfo;
import com.alax.interfaces.service.IApiInfoService;
import com.alax.common.utils.poi.ExcelUtil;
import com.alax.common.core.page.TableDataInfo;
import com.alax.interfaces.domain.dto.ApiInfoDTO;

/**
 * API信息Controller
 * 
 * @author alax
 * @date 2025-04-03
 */
@RestController
@RequestMapping("/interfaces/interfaceInfo")
public class ApiInfoController extends BaseController
{
    @Autowired
    private IApiInfoService apiInfoService;

    /**
     * 查询API信息列表
     */
    // @PreAuthorize("@ss.hasPermi('interfaces:interfaceInfo:list')") // 暂时注释掉权限，允许所有登录用户访问
    @GetMapping("/list")
    public TableDataInfo list(ApiInfo apiInfo)
    {
        startPage();
        List<ApiInfo> list = apiInfoService.selectApiInfoList(apiInfo);
        return getDataTable(list);
    }

    /**
     * 导出API信息列表
     */
    @PreAuthorize("@ss.hasPermi('interfaces:interfaceInfo:export')")
    @Log(title = "API信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ApiInfo apiInfo)
    {
        List<ApiInfo> list = apiInfoService.selectApiInfoList(apiInfo);
        ExcelUtil<ApiInfo> util = new ExcelUtil<ApiInfo>(ApiInfo.class);
        util.exportExcel(response, list, "API信息数据");
    }

    /**
     * 获取API信息详细信息
     */
   // @PreAuthorize("@ss.hasPermi('interfaces:interfaceInfo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(apiInfoService.selectApiInfoById(id));
    }

    /**
     * 新增API信息
     */
    @PreAuthorize("@ss.hasPermi('interfaces:interfaceInfo:add')")
    @Log(title = "API信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Valid @RequestBody ApiInfoDTO apiInfoDTO)
    {
        return toAjax(apiInfoService.insertApiInfo(apiInfoDTO.toEntity()));
    }

    /**
     * 修改API信息
     */
    @PreAuthorize("@ss.hasPermi('interfaces:interfaceInfo:edit')")
    @Log(title = "API信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Valid @RequestBody ApiInfoDTO apiInfoDTO)
    {
        return toAjax(apiInfoService.updateApiInfo(apiInfoDTO.toEntity()));
    }

    /**
     * 删除API信息
     */
    @PreAuthorize("@ss.hasPermi('interfaces:interfaceInfo:remove')")
    @Log(title = "API信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(apiInfoService.deleteApiInfoByIds(ids));
    }
}
